home *** CD-ROM | disk | FTP | other *** search
- Path: news.uoregon.edu!newsadmin@news.uoregon.edu
- From: Pat O'Connor <pwoc@darkwing.uoregon.edu>
- Newsgroups: comp.lang.c
- Subject: Something about typedef and functions I don't understand
- Date: 1 Mar 1996 07:30:12 GMT
- Organization: University of Oregon
- Message-ID: <4h6924$ihl@pith.uoregon.edu>
- NNTP-Posting-Host: darkwing.uoregon.edu
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 5.4 sun4m)
- X-URL: news:comp.lang.c
-
- I just ran into a problem using typedef for declaring aliases for function
- types. Now, I thought that when I say for example,
- typedef double (*DFunc)(double x);
- that I could use DFunc to declare (but not define) functions. But.... when
- I try to compile the following program, the linker has a fit. (granted,
- the program is pretty stupid - I just wanted to simplify things as much as
- possible).
-
- in file 1 in file 2
- -------------------------- --------------------------
- #include <stdio.h> double f(double x) { return x*x;}
-
- typedef double (*DFunc)(double x);
- double DoFunction(DFunc f, double x)
- { return f(x); }
-
- extern DFunc f;
- main()
- {
- printf("%f\n",DoFunction(f,3.0));
- return 0;
- }
-
- Now, if I replace the line "extern DFunc f;" with the line
- "extern double f(double x);" the program compiles and runs fine. So,
- basically, my question is why is it an error to use "extern DFunc f;"
- here?
-
- Thanks.
-
- Pat
-
-
-
- --
- \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/ \/\/
- ___ __ ___
- \ \ / \ / / Who says W is a boson? Why should W be relegated
- \ \ / \ / / to the end of the alphabet? Find out the truth
- \ /\ / long supressed by the elitist alphas and betas!
- \ / \ / Send $10 and a SASE to:
- --- ---
- National Free W League
- 2820 High Street
- Eugene, OR 97405
-
-